package com.block.datapush.special.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.block.datapush.common.enums.FilterErrorEnum;
import com.block.datapush.common.model.result.FilterHandlerResult;
import com.block.datapush.special.service.ISpecialDataMatchInfoService;
import com.block.db.entity.SpecialCostomItemInfo;
import com.block.db.entity.SpecialDataMatchInfo;
import com.block.db.mapper.SpecialDataMatchInfoMapper;
import org.springframework.stereotype.Service;

import java.time.LocalDate;

/**
 * <p>
 * 机构数据匹配记录 服务实现类
 * </p>
 *
 * @author 
 * @since 2023-04-24
 */
@Service
public class SpecialDataMatchInfoServiceImpl extends ServiceImpl<SpecialDataMatchInfoMapper, SpecialDataMatchInfo> implements ISpecialDataMatchInfoService {

    @Override
    public void saveMatchInfo( SpecialCostomItemInfo itemInfo, Long uid, FilterHandlerResult handlerResult){

        if (handlerResult.isSuccess()){
            return;
        }

        FilterErrorEnum result = handlerResult.getResult();
        if (!FilterErrorEnum.isNeedHandle(result)){
            // 错误原因不用处理
            return;
        }

        SpecialDataMatchInfo matchInfo = new SpecialDataMatchInfo();
        matchInfo.setDateInfo(LocalDate.now().toString());
        matchInfo.setInfoId(itemInfo.getInfoId());
        matchInfo.setInfoType(itemInfo.getInfoType());
        matchInfo.setItemId(itemInfo.getId());
        matchInfo.setUid(uid);
        matchInfo.setResult(result.getResult());
        matchInfo.setMessage(handlerResult.getMessage());

        this.save(matchInfo);
    }

    @Override
    public void savePushResultMatchInfo(SpecialCostomItemInfo itemInfo, Long uid, FilterErrorEnum filterErrorEnum, String message) {
        SpecialDataMatchInfo matchInfo = new SpecialDataMatchInfo();
        matchInfo.setDateInfo(LocalDate.now().toString());
        matchInfo.setInfoId(itemInfo.getInfoId());
        matchInfo.setInfoType(itemInfo.getInfoType());
        matchInfo.setItemId(itemInfo.getId());
        matchInfo.setUid(uid);
        matchInfo.setResult(filterErrorEnum.getResult());
        matchInfo.setMessage(message);

        this.save(matchInfo);
    }

}
